<html lang="zh-CN">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>稻荷社区入站答题募集</title>
    <link rel="icon" href="../icon.png" sizes="any" />
    <link rel="stylesheet" href="css/style.css"/>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script>
        function nopic_trigger() {
            document.getElementById('upload_div').style.display = 'none';
            document.getElementById('upload_info').innerHTML = '';
        }

        function withpic_trigger() {
            document.getElementById('upload_div').style.display = 'block';
        }

        function submit_reset() {
            document.getElementById('question_upload').submit();
            document.getElementsByName('question')[0].value = '';
            document.getElementsByName('correct_ans')[0].value = '';
            document.getElementsByName('ans_2')[0].value = '';
            document.getElementsByName('ans_3')[0].value = '';
            document.getElementsByName('ans_4')[0].value = '';
            document.getElementById('withpic').checked = false;
            document.getElementById('nopic').checked = true;
            document.getElementById('picurl').value = '';
            document.getElementById('upload_info').innerHTML = '';
            document.getElementById('captcha_img').click();
            document.getElementsByName('captcha')[0].value = '';
            document.getElementById('captcha_info').innerHTML="";
            nopic_trigger();
        }

        function uploadquestion_ajax() {
            var with_pic = false;
            if (document.getElementsByName('question')[0].value == '') {
                alert("请完善题干信息！");
                return false;
            }
            else if (
                document.getElementsByName('correct_ans')[0].value == ''
                | document.getElementsByName('ans_2')[0].value == ''
                | document.getElementsByName('ans_3')[0].value == ''
                | document.getElementsByName('ans_4')[0].value == ''
            ) {
                alert("请完善选项信息！");
                return false;
            }
            else if (document.getElementsByName('author')[0].value == '') {
                alert("请填写出题人！");
                return false;
            }
            else {
                var form = document.getElementById('captcha'),
                    formData = new FormData(form);
                $.ajax({
                    url: "../captcha/captcha_check.php",
                    type: "post",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (res) {
                        if (res=='1') {
                            document.getElementById('captcha_info').innerHTML="验证码正确！";
                            if (document.getElementById('withpic').checked) {
                                if (document.getElementById('picurl').value == '') {
                                    uploadPic();
                                }
                            }
                            else if (document.getElementById('nopic').checked) {
                                document.getElementById('picurl').value = '';
                                submit_reset();
                            }
                        }
                        else if(res=='0'){
                            document.getElementById('captcha_info').innerHTML="验证码错误！";
                        }
                    },
                    error: function (err) {
                        alert("验证码后台连接失败", err);
                    }
                });
            }
        }

        function uploadPic() {
            if (document.getElementById('pic').value == '') {
                alert("请选择要上传的图片！");
                return false;
            }

            var form = document.getElementById('pic_upload'),
                formData = new FormData(form);
            document.getElementById('upload_info').innerHTML = '正在上传...';
            $.ajax({
                url: "https://file.drmt.xyz/images",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res) {
                        //alert("上传成功！");
                        domparser = new DOMParser();
                        doc = domparser.parseFromString(res, 'text/html');
                        pic_url = doc.getElementsByClassName('mdui-textfield-input')[0].value;
                        console.log(pic_url);
                    }
                    $("#pic").val("");
                    $(".showUrl").val(pic_url);
                    //$(".showPic").attr("src", pic_url);
                    submit_reset();
                },
                error: function (err) {
                    alert("网络连接失败,稍后重试", err);
                }

            })
        }
    </script>
</head>

<body>
    <div id="main">
    <div id="title">稻荷社区入站答题募集</div>
    <div id="header">
        这里可以为稻荷社区<a href="..">入站题库</a>进行投稿~<br>
        请大家稍微把握一下题目难度哦~不要太难<br>
        所有题目都会经过审核才能收录到题库<br>
        不适合作为入站题的题目会收录到<a href="../hard/">"地狱难度"</a>版本<br>
        图片验证码 防止服务器被爆破<br>
        新增题目标签选择 方便后续开发<br>
        （比如说让用户选择自己擅长的分类什么的）<br>
        也欢迎大家来反馈bug~<br>
    </div>
    <div id="editor">
        <form id="question_upload" method="POST" action="server.php" target="post_info">
            <div class="block">
                <div class="lable">题目:</div>
                <textarea name="question" class="bigbox textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <div class="lable">正确答案:</div>
                <textarea name="correct_ans" class="smallbox textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <div class="lable">错误答案1:</div>
                <textarea name="ans_2" class="smallbox textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <div class="lable">错误答案2:</div>
                <textarea name="ans_3" class="smallbox textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <div class="lable">错误答案3:</div>
                <textarea name="ans_4" class="smallbox textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <div class="lable">相关标签:</div>
                <div class="q_classify">
                    <div class="column1">
                        <input id="Kanon" type="checkbox" name="classify" value="Kanon" form="question_upload">
                            <label for="Kanon">Kanon系列</label>
                        </input><br>
                        <input id="Air" type="checkbox" name="classify" value="Air" form="question_upload">
                            <label for="Air">Air系列</label>
                        </input><br>
                        <input id="Clannad_TA" type="checkbox" name="classify" value="Clannad_TA" form="question_upload">
                            <label for="Clannad_TA">Clannad/TA系列</label>
                        </input><br>
                        <input id="planetarian" type="checkbox" name="classify" value="planetarian" form="question_upload">
                            <label for="planetarian">星之梦系列</label>
                        </input><br>
                        <input id="LittleBusters_KW" type="checkbox" name="classify" value="LittleBusters_KW" form="question_upload">
                            <label for="LittleBusters_KW">Little Busters!/KW系列</label>
                        </input><br>
                        <input id="AngelBeats" type="checkbox" name="classify" value="AngelBeats" form="question_upload">
                            <label for="AngelBeats">Angel Beats!系列</label>
                        </input><br>
                        <input id="Rewrite" type="checkbox" name="classify" value="Rewrite" form="question_upload">
                            <label for="Rewrite">Rewrite系列</label>
                        </input><br>
                        <input id="Charlotte" type="checkbox" name="classify" value="Charlotte" form="question_upload">
                            <label for="Charlotte">Charlotte系列</label>
                        </input><br>
                        <input id="Harmonia" type="checkbox" name="classify" value="Harmonia" form="question_upload">
                            <label for="Harmonia">Harmonia系列</label>
                        </input><br>
                        <input id="SummerPockets" type="checkbox" name="classify" value="SummerPockets" form="question_upload">
                            <label for="SummerPockets">Summer Pockets系列</label>
                        </input><br>
                        <input id="Kami_hi" type="checkbox" name="classify" value="Kami_hi" form="question_upload">
                            <label for="Kami_hi">成神之日系列</label>
                        </input>
                    </div>
                    <div class="column2">
                        <input id="Loopers" type="checkbox" name="classify" value="Loopers" form="question_upload">
                            <label for="Loopers">Loopers系列</label>
                        </input><br>
                        <input id="PrimaDoll" type="checkbox" name="classify" value="PrimaDoll" form="question_upload">
                            <label for="PrimaDoll">Prima Doll系列</label>
                        </input><br>
                        <input id="Kaginado" type="checkbox" name="classify" value="Kaginado" form="question_upload">
                            <label for="Kaginado">键等系列</label>
                        </input><br>
                        <input id="LUNARiA" type="checkbox" name="classify" value="LUNARiA" form="question_upload">
                            <label for="LUNARiA">LUNARiA系列</label>
                        </input><br>
                        <input id="HBR" type="checkbox" name="classify" value="HBR" form="question_upload">
                            <label for="HBR">Heaven Burns Red系列</label>
                        </input><br>
                        <input id="Stella" type="checkbox" name="classify" value="Stella" form="question_upload">
                            <label for="Stella">星之终途系列</label>
                        </input><br>
                        <input id="pre_Key" type="checkbox" name="classify" value="pre_KEy" form="question_upload">
                            <label for="pre_Key">Key前身相关</label>
                        </input><br>
                        <input id="Staff" type="checkbox" name="classify" value="Satff" form="question_upload">
                            <label for="Staff">CV/Staff相关</label>
                        </input><br>
                        <input id="Music" type="checkbox" name="classify" value="Music" form="question_upload">
                            <label for="Music">KSL/音乐相关</label>
                        </input><br>
                        <input id="other" type="checkbox" name="classify" value="other" form="question_upload">
                            <label for="other">其他</label>
                        </input>
                    </div>
                </div>
            </div>
            <div class="block">
                <div class="lable">出题人:</div>
                <textarea name="author" class="box textin" form="question_upload" required></textarea>
            </div>
            <div class="block">
                <input id="nopic" type="radio" name="with_pic" value="0" onclick="nopic_trigger()"
                    form="question_upload" checked>
                <label for="nopic">无图片</label>
                </input>
                <input id="withpic" type="radio" name="with_pic" value="1" onclick="withpic_trigger()"
                    form="question_upload">
                <label for="withpic">有图片</label>
                </input>
                <div id="upload_div" style="display:none">
                    <input type="file" name="file" id="pic" form="pic_upload" />
                    <!--<input type="button" value="上传图片" onclick="uploadPic()" form="pic_upload"/>-->
                    <br>
                    <!--<label>图片链接(会自动生成)</lable>-->
                    <input id="picurl" type="text" name="picurl" class="showUrl" form="question_upload"
                        style="display:none"></input>
                    <span id="upload_info"></span>
                    <!--   <img src="" class="showPic" alt=""> -->
                </div>
            </div>
            <div class="block">
                <div class="lable">验证码:</div>
                <img id="captcha_img" src="../captcha/captcha.php" onclick="this.src='../captcha/captcha.php?'+new Date().getTime();"
                    width="200"><br />
                <input id="verify" type="text" name="captcha" placeholder="验证码" form="captcha" class="textin">
                <input itype="text" form="captcha" style="display:none" />
                <span id="captcha_info"></span>
            </div>
        </form>
        <form id="pic_upload" enctype="multipart/form-data" method="post">
        </form>
        <form id="captcha" action="../captcha/captcha_check.php" method="POST" target="result">
        </form>

        <br>
        <input class="submit_buttom" type="button" value="提交" onclick="uploadquestion_ajax()" form="question_upload">
        <br>
        <iframe name="post_info" frameborder="0"></iframe>


    </div></div>
</body>

</html>